home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 90 / CD Actual 90.iso / Software3D / K-3D / k3d-0.4.2.1 / shaders / k3d_fire.sl < prev    next >
Encoding:
Text File  |  2004-07-23  |  1.3 KB  |  54 lines

  1. /* fire.sl
  2.  *
  3.  * animated fire -- adpated from shader by Flip Phillips
  4.  *
  5.  */
  6.  
  7. #include "k3d_rmannotes.h"
  8.  
  9. surface k3d_fire(float frame = 1)
  10. {
  11.   color layer_color, surface_color;
  12.   color surface_opac, layer_opac;
  13.   float width, cutoff, fade, f, turb, maxfreq = 16;
  14.   float flame;
  15.   float ss, tt;
  16.   color red = color (1, .3, .1);
  17.   color orange = color (.95, .7, .05);
  18.   color yellow = color (.95, .95, .1);
  19.   color hot = color (1, 1, .8);
  20.  
  21.   surface_color = 0;
  22.   surface_opac = 0;
  23.  
  24.   /* compress ss & offset both by factor of current frame */
  25.  
  26.   ss = s * 5 + frame * 0.01;
  27.   tt = t + frame * 0.1;
  28.  
  29.   /* compute turbulence */
  30.  
  31.   width = max(filterwidth(ss), filterwidth(tt));
  32.   cutoff = clamp(0.5 / width, 0, maxfreq);
  33.  
  34.   turb = 0;
  35.   for (f = 1; f < 0.5 * cutoff; f *= 2) 
  36.     turb += abs(snoise2(ss * f, tt * f)) / f;
  37.   fade = clamp(2 * (cutoff - f) / cutoff, 0, 1);
  38.   turb += fade * abs(snoise2(ss * f, tt * f)) / f;
  39.   turb *= 0.5;
  40.  
  41.   /* index into color spline using turbulence */
  42.  
  43.   flame = clamp(t - turb, 0, 1);
  44.   layer_opac = flame;
  45.   layer_color = spline(flame, red, red, red, red, orange, yellow, hot, hot);
  46.   surface_color = blend(surface_color, layer_color, layer_opac);
  47.   surface_opac = union(surface_opac, layer_opac);
  48.  
  49.   /* output */
  50.  
  51.   Oi = surface_opac;
  52.   Ci = surface_color;
  53. }
  54.